package com.ciban.smarthome.module.db.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import com.ciban.smarthome.module.db.DbBaseDao;
import com.ciban.smarthome.module.entity.Equip_Monitor_Dh;
import com.ciban.smarthome.module.entity.Equip_Projector;

import java.util.ArrayList;

/**
 * Created by wdl on 2015/11/11.
 * 大华摄像头的数据库类
 */
public class MonitorDao_DH extends DbBaseDao{

    /*camera_dh(_id integer, scene_id integer default -1,status integer,
    user varchar(30),pwd varchar(30),ip varchar(30),port varchar(10))*/

    public MonitorDao_DH(Context context) {
        super(context, "camera_dh");
    }

    public long addNewCamera(Equip_Monitor_Dh info){
        ContentValues values=new ContentValues();
        values.put("_id",info.getId());
        values.put("scene_id",info.getScene_id());
        values.put("status",info.getStatus());
        values.put("user",info.getUser());
        values.put("pwd",info.getPwd());
        values.put("ip",info.getIp());
        values.put("port", info.getPort());

        return insert(null,values);
    }

    public ArrayList<Equip_Monitor_Dh> getCamerDetails(String area_id, int type){
        ArrayList<Equip_Monitor_Dh> list=new ArrayList<Equip_Monitor_Dh>();
        String sql="select  e.[_id],e.[area_id],e.[icon],e.[name],e.[serial_num],e.[type],l.[scene_id],l.[status],l.[user],l.[pwd],l.[ip],l.[port]   from equipment e,camera_dh l where e.[type]=? and e.[area_id]=? and l.[scene_id]=-1 and e.[_id]=l.[_id] ";
        Cursor cursor = execRawQuery(sql, new String[]{type + "", area_id});
        if (cursor != null) {
            Equip_Monitor_Dh info;
            while (cursor.moveToNext()) {
                info = new Equip_Monitor_Dh();
                info.setId(cursor.getString(0));
                info.setArea_id(cursor.getString(1));
                info.setIcon_path(cursor.getString(2));
                info.setName(cursor.getString(3));
                info.setSerial_no(cursor.getInt(4));
                info.setType(cursor.getInt(5));
                info.setScene_id(cursor.getString(6));
                info.setStatus(cursor.getInt(7));
                info.setUser(cursor.getString(8));
                info.setPwd(cursor.getString(9));
                info.setIp(cursor.getString(10));
                info.setPort(cursor.getString(11));

                list.add(info);
            }
        }
        return list;
    }

}
